import java.util.*;
import java.lang.*;
import java.io.*;

public class ContainerMessage
{
  protected String Content;
  protected String Language;
  protected String Ontology;
  protected String Protocol;
  protected String Receiver;
  protected String Sender;
  protected int Performative;

  public static final int INFORM = 0;
  public static final int QUERY = 1;
  
  // TODO more to be added as needed, might go ahead and add all of them
  // from the book.

  public ContainerMessage(int Performative, String Sender)
  {
    this.Performative = Performative;
    this.Sender       = Sender;
    this.Content      = null;
    this.Language     = null;
    this.Ontology     = null;
    this.Protocol     = null;
    this.Receiver     = null;
  }

  public ContainerMessage(int Performative, String Sender, String Receiver,
      String Ontology, String Language, String Protocol, String Content)
  {
    this.Performative = Performative;
    this.Sender       = Sender;
    this.Receiver     = Receiver;
    this.Ontology     = Ontology;
    this.Language     = Language;
    this.Protocol     = Protocol;
    this.Content      = Content;
  }

  public ContainerMessage(ContainerMessage obj)
  {
    this.Performative = obj.Performative;
    this.Sender       = obj.Sender;
    this.Receiver     = obj.Receiver;
    this.Ontology     = obj.Ontology;
    this.Language     = obj.Language;
    this.Protocol     = obj.Protocol;
    this.Content      = obj.Content;
  }

  public ContainerMessage(String TokenizedContainerMessage, String delim)
  {
    StringTokenizer st = new StringTokenizer(TokenizedContainerMessage,delim);
    this.Performative  = Integer.parseInt(st.nextToken());
    this.Sender        = st.nextToken();
    this.Receiver      = st.nextToken();
    this.Ontology      = st.nextToken();
    this.Language      = st.nextToken();
    this.Protocol      = st.nextToken();
    this.Content       = st.nextToken();
  }

  /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   ~                          END CONSTRUCTORS                               ~
   ~                      BEGIN TOSTRING TOMESSAGE                           ~
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

  public String toMessage(String delim)
  {
    String message = Performative + delim +
                     Sender + delim +
                     Receiver + delim +
                     Ontology + delim +
                     Language + delim +
                     Protocol + delim +
                     Content;
    return message;
  }

  public String toString()
  {
    String str = "( " + Performative + ":\n" +
                      "\tSender:\t\t( " + Sender + " )\n" +
                      "\tReceiver:\t( ";
    if (Sender.equals("null"))
      str += "null";
    else
      str += Sender;
    str +=            " )\n" +
                      "\tOntology:\t" + Ontology + "\n" +
                      "\tLanguage:\t" + Language + "\n" +
                      "\tProtocol:\t" + Protocol + "\n" +
                      "\tContent:\t" + Content + "\n)";
    return str;
  }

  /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   ~                          END TOSTRING TOMESSAGE                         ~
   ~                       BEGIN ACCESSORS AND MUTATORS                      ~
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/



  


  public void setContent(String Content)
  {
    this.Content = Content;
  }

  public void setLanguage(String Language)
  {
    this.Language = Language;
  }

  public void setOntology(String Ontology)
  {
    this.Ontology = Ontology;
  }

  public void setProtocol(String Protocol)
  {
    this.Protocol = Protocol;
  }

  public void setReceiver(String Receiver)
  {
    this.Receiver = Receiver;
  }
  
  //YOU SHOULD NEVER HAVE TO USE THESE NEXT TWO:
  public void setSender(String Sender)
  {
    this.Sender = Sender;
  }

  public void setPerformative(int Performative)
  {
    this.Performative = Performative;
  }

  //---------------------------------ACCESORSS--------------------------------

  public String getContent()
  {
    return Content;
  }

  public String getLangauge()
  {
    return Language;
  }

  public String getOntology()
  {
    return Ontology;
  }

  public String getProtocol()
  {
    return Protocol;
  }

  public String getReceiver()
  {
    return Receiver;
  }

  public String getSender()
  {
    return Sender;
  }

  public int getPerformative()
  {
    return Performative;
  }

  /* This should be good for this class, but if there are any other problems
   * I will edit it later and add more content to it that we might think is
   * needed */

}
